package com.charonmc.utils;

import lombok.Getter;
import lombok.Setter;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;

public class VanishUtils
{
    @Getter
    @Setter
    private static ArrayList<Player> VanishPlayers = new ArrayList<>();

    public static void setPlayerVanish(Player player) {
        if (!VanishPlayers.contains(player)) {
            VanishPlayers.add(player);
            for (Player key : Bukkit.getOnlinePlayers()) {
                if (!key.hasPermission("Core.Vanish")) {
                    key.hidePlayer(player);
                }
            }
            player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 9999999, 1), true);
        }
    }

    public static void removePlayerVanish(Player player){
        VanishPlayers.remove(player);
        for (Player key : Bukkit.getOnlinePlayers()) {
            if (!key.hasPermission("Core.Vanish")) {
                key.showPlayer(player);
            }
        }
        player.removePotionEffect(PotionEffectType.INVISIBILITY);
    }
    public static IChatBaseComponent getChatBaseComponent() {
        return IChatBaseComponent.ChatSerializer.a("§c§l您正处于隐身状态");
    }
}
